import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class getgap {

	public static void main(String[] args) {
		String input = args[0];
		readfile(input);
	}
	
	public static void readfile(String input) {
		try(BufferedReader br = new BufferedReader(new FileReader(input))){
			String line;
			int last_ref_end = -1;
			int last_qry_end = -1;
			int last_qry_start = -1;
			String id = "";
			String strand = "";
			while((line = br.readLine()) != null) {
				String[] strs = line.split("\\s+");
				String qry_id = strs[0];
				String ref_id = strs[3];
				int qry_start = Integer.parseInt(strs[1]);
				int qry_end = Integer.parseInt(strs[2]);
				int ref_start = Integer.parseInt(strs[4]);
				int ref_end = Integer.parseInt(strs[5]);
				if(qry_id.equals(id)) {
					if(last_ref_end > 0) {
						if(ref_start - last_ref_end >= 1000) {
							if(strand.equals("+")) {
								System.out.println(qry_id + "\t" + last_qry_end + "\t" + qry_start + "\t" + 
										ref_id + "\t" + last_ref_end + "\t" + ref_start + "\t" + strand);
							}else {
								System.out.println(qry_id + "\t" + last_qry_start + "\t" + qry_start + "\t" + 
										ref_id + "\t" + last_ref_end + "\t" + ref_start + "\t" + strand);
							}
							
						}
					}
				}else {
					id = qry_id;
					strand = strs[6];
				}
				last_qry_end = qry_end;
				last_qry_start = qry_end;
				last_ref_end = ref_end;
			}
		}catch(IOException e) {
			e.printStackTrace();
		}
	}

}
